﻿<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/easyui/_easyui.jsp" %>
<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>欢迎登录后台管理系统</title>
    <link href="${basePath}resources/css/style.css" rel="stylesheet" type="text/css"/>
    <script src="${basePath}resources/js/cloud.js" type="text/javascript"></script>

</head>

<body style="background-color:#1c77ac;
        background-image:url(${basePath}resources/images/web/light.png);
        background-repeat:no-repeat; background-position:center top; overflow:hidden;">

<div id="mainBody">
    <div id="cloud1" class="cloud"></div>
    <div id="cloud2" class="cloud"></div>
</div>

<div class="logintop">
    <span>欢迎使用游艺云平台</span>
</div>

<div class="loginbody">
    <span class="systemlogo"></span>

    <div class="loginbox">
        <form id="myForm" name="myForm">
            <ul>
                <li><input id="username" name="username" type="text"
                           class="loginuser" placeholder="用户名 / 手机号"/></li>
                <li>
                    <input id="password" type="password" class="loginpwd" placeholder="密码"/>
                    <input type="hidden" id="loginpassword" name="password">
                </li>
                <li>
                    <input id="valid" name="vildCode" type="text" class="loginuser" placeholder="验证码"/>
                    <img id="captchaImage" class="captchaImage" src="${basePath}authCode" alt=""
                         style="vertical-align:middle;" onclick="chageCode()"/>
                </li>

                <li>
                    <div id="logintext" style="color: red;"></div>
                </li>
                <li>
                    <input type="button" class="loginbtn" value="登录" id="login_submit"/>
                    <a class="loginbtn" href="${basePath}register/gotoRegister"
                       style="margin-left:20px;vertical-align:middle">立即注册</a>
                </li>
            </ul>
        </form>
    </div>
</div>

<script type="application/javascript">

    $(function () {
        $('.loginbox').css({
            'position': 'absolute',
            'left': ($(window).width() - 692) / 2
        });
        $(window).resize(function () {
            $('.loginbox').css({
                'position': 'absolute',
                'left': ($(window).width() - 692) / 2
            });
        })
    });

    function chageCode() {
        $('#captchaImage').attr('src', '${basePath}authCode?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
    }

    $("#login_submit").click(function () {
        var username = $("#username").val();

        var password = $("#password").val();

        var vaild = $("#valid").val();

        if (typeof(username) == "undefined" || username.length == 0) {
            $("#logintext").text("用户名不能为空");
        } else if (typeof(password) == "undefined" || password.length == 0) {
            $("#logintext").text("密码不能为空");
        } else if (typeof(vaild) == "undefined" || vaild.length == 0) {
            $("#logintext").text("验证码不能为空");
        } else {
            $("#loginpassword").val(createPassword(password, password));
            console.info($("#loginpassword").val());
            $.ajax({
                url: '${basePath}signin',
                type: 'POST',
                data: $("#myForm").serialize(),
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if (ret.result) {
                        window.location = "index";
                    } else {
                        $("#logintext").text(ret.info);
                        /!* $.messager.alert('温馨提醒',ret.info,'error'); *!/
                    }
                }
            });
        }
    });

    $("#login_test").click(function () {
        $.ajax({
            url: '${basePath}index',
            type: 'GET',
            error: function (response) {
                console.log("error:" + response);
            }, success: function (ret) {
                console.log("success:" + ret);
            }
        });

    });

</script>
</body>

</html>
